package com.ayou.eggguard.farm.service.impl;

import com.ayou.common.utils.PageBean;
import com.ayou.eggguard.farm.mapper.TradeMapper;
import com.ayou.eggguard.farm.pojo.Trade;
import com.ayou.eggguard.farm.service.TradeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TradeServiceImpl implements TradeService {
    @Autowired
    private TradeMapper tradeMapper;

    @Override
    public PageBean<Trade> getTrades(Integer pageNum, Integer pageSize, String orderNumber) {
        PageBean<Trade> pb=new PageBean<>();

        PageHelper.startPage(pageNum,pageSize);

        List<Trade> list=tradeMapper.getTrades(orderNumber);
        Page<Trade> p= (Page<Trade>) list;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;

    }

    @Override
    public void add(Trade trade) {
        tradeMapper.add(trade);
    }

    @Override
    public void update(Trade trade) {
        tradeMapper.update(trade);
    }

    @Override
    public void delete(Integer tradeId) {
        tradeMapper.delete(tradeId);
    }
}
